package text111;

import java.util.HashMap;

public class Solution49 {
    public int majorityElement(int[] nums) {
    	//创建hash列表，返回值res
    	HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
    	int res = 0;
    	//数组数放入hash列表重复出现的数value加1
    	for (int i = 0; i < nums.length; i++) {
    		int key = nums[i];
    		if (!map.containsKey(key)) {
				map.put(key, 1);
			}else {
				map.put(key, map.get(key)+1);
			}
		}
    	//遍历列表，返回value大于数组长度一半key值
    	for (Integer i: map.keySet()) {
			if (map.get(i)>nums.length/2) {
				res = i;
			}
		}
		return res;
    }
}
